
package com.xinzhidi.web.city.controller;

import com.xinzhidi.common.core.controller.BaseController;
import com.xinzhidi.common.core.domain.AjaxResult;
import com.xinzhidi.web.city.domain.AllAddress;
import com.xinzhidi.web.city.domain.City;
import com.xinzhidi.web.city.domain.vo.CityVo;
import com.xinzhidi.web.city.service.CityService;
import com.xinzhidi.web.city.service.CityWeatherService;
import com.xinzhidi.web.plot.domain.entity.CPlot;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName CityController
 * @Description: 省市管理控制器
 * @Author cx
 * @Date 2023-05-23 00:03
 * @Version V1.0
 **/
@Api(value = "省市接口", tags = "(公共)省市地址接口")
@RestController
@RequestMapping("/city")
@RequiredArgsConstructor
public class CityController extends BaseController {

    private final static Logger logger = LoggerFactory.getLogger(CityController.class);
    private final CityService cityService;

    private final CityWeatherService cityWeatherService;

    @ApiOperation("获取省份列表")
    @GetMapping("/getProvinceList")
    public AjaxResult getProvinceList() {
        logger.info("获取省份列表");
        List<City> provinceList = cityService.getCityList(0);
        return AjaxResult.success(provinceList);
    }

    @ApiOperation("根据省份ID获取城市(地区)列表")
    @GetMapping("/getCityList")
    public AjaxResult getCityList(@ApiParam(value = "省份ID、市ID") @RequestParam("pid") Integer pid) {
        logger.info("根据省份ID获取城市列表");
        List<City> CityList = cityService.getCityList(pid);
        return AjaxResult.success(CityList);
    }

    @ApiOperation("根据地区ID 获取小区列表")
    @GetMapping("/getPoltList")
    public AjaxResult getPoltList(@ApiParam(value = "地区ID") @RequestParam("area") String area) {
        logger.info("根据地区ID 获取小区列表");
        List<CPlot> regionList = cityService.getPlotListByRegion(area);
        return AjaxResult.success(regionList);
    }

    @ApiOperation("获取省市区三级地址list")
    @GetMapping("/getAllAddress")
    public AjaxResult getAllAddress() {
        logger.info("获取省市区三级地址list");
        AllAddress allAddress = cityService.getAllAddress();
        return AjaxResult.success(allAddress);
    }

    @ApiOperation("获取省市区三级地址树形结构数据")
    @GetMapping("/getCityTreeList")
    public AjaxResult getCityTreeList(){
        List<CityVo> list = cityService.getCityTreeList();
        return AjaxResult.success(list);
    }


    @ApiOperation("保存天气")
    @GetMapping("/weatherSaveTask")
    public AjaxResult weatherSaveTask(){
        cityWeatherService.weatherSaveTask();
        return AjaxResult.success();
    }

}
